package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chixing.commons.ServerResponse;
import com.chixing.mapper.CompanyDetailMapper;
import com.chixing.mapper.JobDetailMapper;
import com.chixing.pojo.*;
import com.chixing.service.IJobDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 职位详情表 服务实现类
 * </p>
 *
 * @author Jason Marslyon
 * @since 2022-10-04
 */
@Service
public class JobDetailServiceImpl implements IJobDetailService {
    @Autowired
    private JobDetailMapper jobDetailMapper;
    @Autowired
    private CompanyDetailMapper companyDetailMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public ServerResponse selectJob(int jobId) {
        JobDetail jobDetail=jobDetailMapper.selectById(jobId);
        CompanyDetail companyDetail=companyDetailMapper.selectById(jobDetail.getCompanyId());
        JobAndCompany jobAndCompany=new JobAndCompany(jobDetail,companyDetail);
        return ServerResponse.success("success",jobAndCompany);
    }
//获取全部数据（不筛选）
    @Override
    public ServerResponse selectAllJobs(Integer pageNum) {
      ValueOperations<String, PageInfo<EsJobCompany>> valueOperations = redisTemplate.opsForValue();
        String key = "jobAll_"+pageNum;
        if (!redisTemplate.hasKey(key)) {
            QueryWrapper<CompanyDetail> wrapper = new QueryWrapper();
            QueryWrapper<JobDetail> wrapper1 = new QueryWrapper<>();
            PageHelper.startPage(pageNum, 7);
            List<JobDetail> jobDetailList = jobDetailMapper.selectList(null);
            List<EsJobCompany> list = new ArrayList<>();
            PageInfo<JobDetail> pageInfo = new PageInfo<>(jobDetailList);
//        System.out.println(pageInfo);
            for (JobDetail jobdetail : jobDetailList) {
                CompanyDetail companyDetail = companyDetailMapper.selectById(jobdetail.getCompanyId());
                EsJobCompany esJobCompany = new EsJobCompany();
                esJobCompany.setCompanyImg(companyDetail.getCompanyImg());
                esJobCompany.setJobDegree(jobdetail.getJobDegree());
                esJobCompany.setJobLocArea(jobdetail.getJobLocArea());
                esJobCompany.setJobMaxSalary(jobdetail.getJobMaxSalary());
                esJobCompany.setJobMinSalary(jobdetail.getJobMinSalary());
                esJobCompany.setCompanyId(companyDetail.getCompanyId());
                esJobCompany.setJobExperience(jobdetail.getJobExperience());
                esJobCompany.setJobName(jobdetail.getJobName());
                esJobCompany.setJobId(jobdetail.getJobId());
                esJobCompany.setCompanyFinance(companyDetail.getCompanyFinance());
                esJobCompany.setCompanyIndustry(companyDetail.getCompanyIndustry());
                esJobCompany.setCompanyScale(companyDetail.getCompanyScale());
                esJobCompany.setCompanyName(companyDetail.getCompanyName());
                esJobCompany.setJobType(jobdetail.getJobType());
                list.add(esJobCompany);
            }
            if (list != null) {
                PageInfo<EsJobCompany> pageInfo1 = new PageInfo<>(list);
                pageInfo1.setPageNum(pageInfo.getPageNum());
//            System.out.println(pageInfo1.getPageNum());
//            jobAndCompanyArrayList.forEach(System.out::println);
//            System.out.println(pageInfo1);

                redisTemplate.opsForValue().set(key, pageInfo1, 1, TimeUnit.HOURS);
                return ServerResponse.success("数据库查询所有成功", pageInfo1);
            }
            return ServerResponse.fail("查询所有失败", null);

        }else{

            System.out.println("************************************************************************");
            return ServerResponse.success("redis查询所有成功", valueOperations.get(key));
        }
    }

    //获取全部数据（筛选）
@Override
public ServerResponse selectAllJob(Integer pageNum,String companyIndustry,String jobDegree,String salary,String jingyan,String companyScale) {
    QueryWrapper<CompanyDetail> wrapper = new QueryWrapper();
    QueryWrapper<JobDetail> wrapper1 = new QueryWrapper<>();
    boolean hasCond = false;
    boolean hasCond1=false;
    System.out.println("companyScale---------------------------------------------------"+companyScale);
    if (!companyIndustry.equals("公司行业")){
        wrapper.eq("company_industry",companyIndustry);
        hasCond =true;
        System.out.println("aaaaaaaaaaaaa");
    }
//        if (!companyIndustry.equals("融资阶段")){
//            wrapper.eq("company_finance",companyFinance);
//            hasCondition =true;
//            System.out.println("ccccccc"+companyFinance);
//        }
    if (!jobDegree.equals("学历要求")){
        wrapper1.eq("job_degree",jobDegree);
        hasCond1 =true;
        System.out.println("bbbbbbbb"+jobDegree);
    }
    if (!companyScale.equals("公司规模")){
        wrapper.eq("company_scale",companyScale);
        hasCond =true;
        System.out.println("wwwwwwwww"+companyScale);
    }
    if (!jingyan.equals("工作经验")){

        wrapper1.eq("job_experience",jingyan);
        hasCond1 =true;
        System.out.println("aqqqqqqqqqqq"+jingyan);
    }
    if (!salary.equals("薪资待遇")){
        System.out.println("--------------"+salary);
        String[] strings = salary.split("-");
        System.out.println(strings[0]);
        float minsalary=Float.valueOf(strings[0]);
        float maxsalary=Float.valueOf(strings[1]);

        wrapper1.between("job_min_salary",minsalary,maxsalary);
        hasCond1 =true;
    }
    if (hasCond == false&& hasCond1==false) {
        PageHelper.startPage(pageNum, 7);
        List<JobDetail> jobDetailList = jobDetailMapper.selectList(wrapper1);
        List<EsJobCompany> list = new ArrayList<>();

        List<CompanyDetail> comlist=companyDetailMapper.selectList(wrapper);
        PageInfo<JobDetail> pageInfo = new PageInfo<>(jobDetailList);
        System.out.println(pageInfo);
        for (JobDetail jobdetail : jobDetailList) {
            PageHelper.startPage(pageNum, 7);

            CompanyDetail companyDetail = companyDetailMapper.selectById(jobdetail.getCompanyId());
            EsJobCompany esJobCompany=new EsJobCompany();
            esJobCompany.setCompanyImg(companyDetail.getCompanyImg());
            esJobCompany.setJobDegree(jobdetail.getJobDegree());
            esJobCompany.setJobLocArea(jobdetail.getJobLocArea());
            esJobCompany.setJobMaxSalary(jobdetail.getJobMaxSalary());
            esJobCompany.setJobMinSalary(jobdetail.getJobMinSalary());
            esJobCompany.setCompanyId(companyDetail.getCompanyId());
            esJobCompany.setJobExperience(jobdetail.getJobExperience());
            esJobCompany.setJobName(jobdetail.getJobName());
            esJobCompany.setJobId(jobdetail.getJobId());
            esJobCompany.setCompanyFinance(companyDetail.getCompanyFinance());
            esJobCompany.setCompanyIndustry(companyDetail.getCompanyIndustry());
            esJobCompany.setCompanyScale(companyDetail.getCompanyScale());
            esJobCompany.setCompanyName(companyDetail.getCompanyName());
            esJobCompany.setJobType(jobdetail.getJobType());
            list.add(esJobCompany);
        }
//            for (CompanyDetail company:comlist) {
//                for (JobDetail jobdetail: jobDetailList) {
//                    if (company.getCompanyId().equals(jobdetail.getCompanyId())) {
//                        JobAndCompany jobAndCompany = new JobAndCompany(jobdetail, company);
//                        jobAndCompanyArrayList.add(jobAndCompany);
//                    }
//                }
//
//            }
        if (list != null) {
            PageInfo<EsJobCompany> pageInfo1 = new PageInfo<>(list);
            pageInfo1.setPageNum(pageInfo.getPageNum());
//                System.out.println(pageInfo1.getPageNum());
//                jobAndCompanyArrayList.forEach(System.out::println);
//                System.out.println(pageInfo1);

            return ServerResponse.success("查询所有成功", pageInfo1);
        }
        return ServerResponse.fail("查询所有失败", null);
    }
    else {
        PageInfo<EsJobCompany> pageInfo=new PageInfo<>();
        System.out.println("执行hascode方法   ------------------------------------------------------------");
if (hasCond1==true && hasCond==false){
    PageHelper.startPage(pageNum, 7);
    List<JobDetail> listjob=jobDetailMapper.selectList(wrapper1);
    List<EsJobCompany> list=new ArrayList<>();
    for (JobDetail jobdetail:listjob
         ) {
        CompanyDetail companyDetail = companyDetailMapper.selectById(jobdetail.getCompanyId());
        EsJobCompany esJobCompany=new EsJobCompany();
        esJobCompany.setCompanyImg(companyDetail.getCompanyImg());
        esJobCompany.setJobDegree(jobdetail.getJobDegree());
        esJobCompany.setJobLocArea(jobdetail.getJobLocArea());
        esJobCompany.setJobMaxSalary(jobdetail.getJobMaxSalary());
        esJobCompany.setJobMinSalary(jobdetail.getJobMinSalary());
        esJobCompany.setCompanyId(companyDetail.getCompanyId());
        esJobCompany.setJobExperience(jobdetail.getJobExperience());
        esJobCompany.setJobName(jobdetail.getJobName());
        esJobCompany.setJobId(jobdetail.getJobId());
        esJobCompany.setJobType(jobdetail.getJobType());
        esJobCompany.setCompanyFinance(companyDetail.getCompanyFinance());
        esJobCompany.setCompanyIndustry(companyDetail.getCompanyIndustry());
        esJobCompany.setCompanyScale(companyDetail.getCompanyScale());
        esJobCompany.setCompanyName(companyDetail.getCompanyName());
        list.add(esJobCompany);
    }

     pageInfo=new PageInfo<>(list);
    return ServerResponse.success("查询所有成功", pageInfo);
}
if (hasCond==true && hasCond1==false){
    List<CompanyDetail> listcoms=companyDetailMapper.selectList(wrapper);
    List<Integer> comIdList=new ArrayList<>();
    for (CompanyDetail com:listcoms
         ) {
        int comId=com.getCompanyId();
        comIdList.add(comId);
    }
    PageHelper.startPage(pageNum,7);
    QueryWrapper<JobDetail> wrapper2=new QueryWrapper<>();
    wrapper2.in("company_id",comIdList);
    List<JobDetail> jobDetailList = jobDetailMapper.selectList(wrapper2);
    List<EsJobCompany> list=new ArrayList<>();
    for (JobDetail jobdetail:jobDetailList
         ) {
        CompanyDetail companyDetail=companyDetailMapper.selectById(jobdetail.getCompanyId());
        EsJobCompany esJobCompany=new EsJobCompany();
        esJobCompany.setCompanyImg(companyDetail.getCompanyImg());
        esJobCompany.setJobDegree(jobdetail.getJobDegree());
        esJobCompany.setJobLocArea(jobdetail.getJobLocArea());
        esJobCompany.setJobMaxSalary(jobdetail.getJobMaxSalary());
        esJobCompany.setJobMinSalary(jobdetail.getJobMinSalary());
        esJobCompany.setCompanyId(companyDetail.getCompanyId());
        esJobCompany.setJobExperience(jobdetail.getJobExperience());
        esJobCompany.setJobName(jobdetail.getJobName());
        esJobCompany.setJobId(jobdetail.getJobId());
        esJobCompany.setCompanyFinance(companyDetail.getCompanyFinance());
        esJobCompany.setCompanyIndustry(companyDetail.getCompanyIndustry());
        esJobCompany.setCompanyScale(companyDetail.getCompanyScale());
        esJobCompany.setCompanyName(companyDetail.getCompanyName());
        list.add(esJobCompany);
    }
     pageInfo=new PageInfo<>(list);
    return ServerResponse.success("查询所有成功", pageInfo);
}
if (hasCond==true && hasCond1==true){
    List<CompanyDetail> listcoms=companyDetailMapper.selectList(wrapper);
    List<Integer> comIdList=new ArrayList<>();
    for (CompanyDetail com:listcoms) {
        int comId=com.getCompanyId();
        comIdList.add(comId);
    }
    System.out.println("******************************************************************");
//    comIdList.forEach(System.out::println);
    System.out.println("******************************************************************");
    PageHelper.startPage(pageNum, 7);
if (comIdList==null){
    pageInfo=new PageInfo<>();
    return ServerResponse.success("查询所有成功", pageInfo);
}else{
    wrapper1.in("company_id",comIdList);
    List<JobDetail> jobDetailList = jobDetailMapper.selectList(wrapper1);
    List<EsJobCompany> list=new ArrayList<>();
    for (JobDetail job:jobDetailList) {
        for (Integer comId : comIdList) {
            if (job.getCompanyId().equals(comId)) {
                JobDetail jobdetail = jobDetailMapper.selectById(job.getJobId());
                CompanyDetail companyDetail = companyDetailMapper.selectById(comId);
                EsJobCompany esJobCompany=new EsJobCompany();
                esJobCompany.setCompanyImg(companyDetail.getCompanyImg());
                esJobCompany.setJobDegree(jobdetail.getJobDegree());
                esJobCompany.setJobLocArea(jobdetail.getJobLocArea());
                esJobCompany.setJobMaxSalary(jobdetail.getJobMaxSalary());
                esJobCompany.setJobMinSalary(jobdetail.getJobMinSalary());
                esJobCompany.setCompanyId(companyDetail.getCompanyId());
                esJobCompany.setJobExperience(jobdetail.getJobExperience());
                esJobCompany.setJobName(jobdetail.getJobName());
                esJobCompany.setJobId(jobdetail.getJobId());
                esJobCompany.setJobType(jobdetail.getJobType());
                esJobCompany.setCompanyFinance(companyDetail.getCompanyFinance());
                esJobCompany.setCompanyIndustry(companyDetail.getCompanyIndustry());
                esJobCompany.setCompanyScale(companyDetail.getCompanyScale());
                esJobCompany.setCompanyName(companyDetail.getCompanyName());
                list.add(esJobCompany);
            }
        }

    }
     pageInfo=new PageInfo<>(list);
    return ServerResponse.success("查询所有成功", pageInfo);
}
}

        return ServerResponse.success("查询所有成功", pageInfo);
    }

}



    @Override
    public ServerResponse getJobDetail(int jobId) {

        JobDetail jobDetail = jobDetailMapper.selectById(jobId);
        CompanyDetail companyDetail=companyDetailMapper.selectById(jobDetail.getCompanyId());
        JobAndCompany jobAndCompany=new JobAndCompany(jobDetail,companyDetail);
        if (jobAndCompany !=null){
            return ServerResponse.success("查询所有成功",jobAndCompany);
        }
        return ServerResponse.fail("查询所有失败",null);

    }


    @Override
    public ServerResponse getJobTotal(String companyIndustry,String jobDegree,String salary,String jingyan,String companyScale) {
        QueryWrapper<CompanyDetail> wrapper=new QueryWrapper();
        QueryWrapper<JobDetail> wrapper1=new QueryWrapper<>();
        System.out.println(companyIndustry);
        boolean hasCondition = false;

        if (!companyIndustry.equals("公司行业")){
            wrapper.eq("company_industry",companyIndustry);
            hasCondition =true;
            System.out.println("aaaaaaaaaaaaa");
        }
//        if (!companyIndustry.equals("融资阶段")){
//            wrapper.eq("company_finance",companyFinance);
//            hasCondition =true;
//            System.out.println("ccccccc"+companyFinance);
//        }
        if (!jobDegree.equals("学历要求")){
            wrapper1.eq("job_degree",jobDegree);
            hasCondition =true;
            System.out.println("bbbbbbbb"+jobDegree);
        }
        if (!companyScale.equals("公司规模")){
            wrapper.eq("company_scale",companyScale);
            hasCondition =true;
            System.out.println("wwwwwwwww"+companyScale);
        }
        if (!jingyan.equals("工作经验")){

            wrapper1.eq("job_experience",jingyan);
            hasCondition =true;
            System.out.println("aqqqqqqqqqqq"+jingyan);
        }
        if (!salary.equals("薪资待遇")){
            System.out.println("--------------"+salary);
            String[] strings = salary.split("-");
            System.out.println(strings[0]);
            float minsalary=Float.valueOf(strings[0]);
            float maxsalary=Float.valueOf(strings[1]);

            wrapper1.between("job_min_salary",minsalary,maxsalary);
            hasCondition =true;
        }
        Long total=0l;
        if (hasCondition==false){
            total = jobDetailMapper.selectCount(null);
        }else{
            System.out.println("执行hasCondition=true的方法");
            List<CompanyDetail> companyDetailList=companyDetailMapper.selectList(wrapper);

            List<JobDetail> jobDetailList = jobDetailMapper.selectList(wrapper1);
            List<EsJobCompany> totallist=new ArrayList<>();
           List<EsJobCompany> list=new ArrayList<>();
            for (CompanyDetail companyDetails:companyDetailList) {

                System.out.println("companyId  ***************************************************************************");
                for (JobDetail jobdetail:jobDetailList) {
                    if (jobdetail.getCompanyId().equals(companyDetails.getCompanyId())){
                        EsJobCompany esJobCompany=new EsJobCompany();
                        esJobCompany.setCompanyImg(companyDetails.getCompanyImg());
                        esJobCompany.setJobDegree(jobdetail.getJobDegree());
                        esJobCompany.setJobLocArea(jobdetail.getJobLocArea());
                        esJobCompany.setJobMaxSalary(jobdetail.getJobMaxSalary());
                        esJobCompany.setJobMinSalary(jobdetail.getJobMinSalary());
                        esJobCompany.setCompanyId(companyDetails.getCompanyId());
                        esJobCompany.setJobExperience(jobdetail.getJobExperience());
                        esJobCompany.setJobName(jobdetail.getJobName());
                        esJobCompany.setJobId(jobdetail.getJobId());
                        esJobCompany.setCompanyFinance(companyDetails.getCompanyFinance());
                        esJobCompany.setCompanyIndustry(companyDetails.getCompanyIndustry());
                        esJobCompany.setCompanyScale(companyDetails.getCompanyScale());
                        esJobCompany.setCompanyName(companyDetails.getCompanyName());
                        totallist.add(esJobCompany);
                        list.add(esJobCompany);
                    }

                }
            }


            total=Long.valueOf(list.size());

        }


        System.out.println("ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"+total);
        return ServerResponse.success("查询总数成功",total);

    }

    @Override
    public ServerResponse getJobTotals() {
        Long total = jobDetailMapper.selectCount(null);
        return ServerResponse.success("查询总数成功",total);
    }

/*    //热数据
    *//*@Cacheable(cacheNames = "hotJobDetail#2000" ,key="'hot_jobdetail'" )*//*
    @Override
    public List<JobDetail> getHotDiscountJob() {
        QueryWrapper<JobDetail> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("job_pub_time");
        wrapper.select("job_id","job_name","job_experience","job_loc_city","job_degree","job_max_salary","job_min_salary");
        //设置分页
        Page<JobDetail> page = new Page<>(1,9);
        Page<JobDetail> pageInfo = jobDetailMapper.selectPage(page,wrapper);
        List<JobDetail> jobDetailList = pageInfo.getRecords();
        System.out.println("从mysql中查询出来的热门: " + jobDetailList);
        return jobDetailList;


    }*/

    @Override
    public List<EsJobCompany> getJobCompany() {
        List<JobDetail> jobDetailList = jobDetailMapper.selectList(null);
        List<EsJobCompany> esJobCompanyList = new ArrayList<>();
        for (JobDetail jobDetail:jobDetailList){
            CompanyDetail companyDetail = companyDetailMapper.selectById(jobDetail.getCompanyId());
            EsJobCompany esJobCompany = new EsJobCompany();
            esJobCompany.setJobId(jobDetail.getJobId());
            esJobCompany.setJobName(jobDetail.getJobName());
            esJobCompany.setJobType(jobDetail.getJobType());
            esJobCompany.setJobMaxSalary(jobDetail.getJobMaxSalary());
            esJobCompany.setJobMinSalary(jobDetail.getJobMinSalary());
            esJobCompany.setJobDegree(jobDetail.getJobDegree());
            esJobCompany.setJobExperience(jobDetail.getJobExperience());
            esJobCompany.setJobLocArea(jobDetail.getJobLocArea());
            esJobCompany.setCompanyId(companyDetail.getCompanyId());
            esJobCompany.setCompanyImg(companyDetail.getCompanyImg());
            esJobCompany.setCompanyName(companyDetail.getCompanyName());
            esJobCompany.setCompanyScale(companyDetail.getCompanyScale());
            esJobCompany.setCompanyIndustry(companyDetail.getCompanyIndustry());
            esJobCompany.setCompanyFinance(companyDetail.getCompanyFinance());
            esJobCompany.setJobType(jobDetail.getJobType());
            esJobCompanyList.add(esJobCompany);
        }
        return esJobCompanyList;
    }
    //模糊搜索的总条数
    @Override
    public ServerResponse selectConfuseNum(String kw) {
        QueryWrapper<JobDetail> wrapper=new QueryWrapper<>();
        wrapper.like("job_name",kw);
        List<JobDetail> jobDetailList = jobDetailMapper.selectList(wrapper);
        int size = jobDetailList.size();
        return ServerResponse.success("查询成功",size);
    }
    //模糊搜索
    @Override
    public ServerResponse selectConfuseJob(String kw,Integer pageNum) {
        QueryWrapper<JobDetail> wrapper=new QueryWrapper<>();
        wrapper.like("job_name",kw);
        PageHelper.startPage(pageNum,7);
        List<JobDetail> jobDetailList = jobDetailMapper.selectList(wrapper);
        List<EsJobCompany> list=new ArrayList<>();
        for (JobDetail job: jobDetailList) {
            CompanyDetail companyDetail = companyDetailMapper.selectById(job.getCompanyId());
            EsJobCompany esJobCompany=new EsJobCompany();
            esJobCompany.setJobType(job.getJobType());
            esJobCompany.setJobId(job.getJobId());
            esJobCompany.setCompanyImg(companyDetail.getCompanyImg());
            esJobCompany.setJobName(job.getJobName());
            esJobCompany.setCompanyScale(companyDetail.getCompanyScale());
            esJobCompany.setCompanyName(companyDetail.getCompanyName());
            esJobCompany.setCompanyFinance(companyDetail.getCompanyFinance());
            esJobCompany.setJobExperience(job.getJobExperience());
            esJobCompany.setJobMinSalary(job.getJobMinSalary());
            esJobCompany.setJobMaxSalary(job.getJobMaxSalary());
            esJobCompany.setCompanyId(companyDetail.getCompanyId());
            esJobCompany.setJobLocArea(job.getJobLocArea());
            esJobCompany.setCompanyIndustry(esJobCompany.getCompanyIndustry());
            esJobCompany.setJobDegree(job.getJobDegree());
            esJobCompany.setJobType(job.getJobType());
            esJobCompany.setCompanyIndustry(companyDetail.getCompanyIndustry());

            list.add(esJobCompany);
        }
        PageInfo<EsJobCompany> pageInfo=new PageInfo<>(list);
        return ServerResponse.success("查询成功",pageInfo);
    }

    @Override
    public JobDetail getJob(Integer id) {
        JobDetail jobDetail = jobDetailMapper.selectById(id);
        return jobDetail;
    }

    @Override
    public CompanyDetail getCompany(Integer id) {
        CompanyDetail companyDetail = companyDetailMapper.selectById(id);
        return companyDetail;
    }

    @Override
    public ServerResponse getNumJob(int size) {
        QueryWrapper<JobDetail> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("job_id").last("limit 1");
        JobDetail job = jobDetailMapper.selectOne(wrapper);
        int jobId= job.getJobId();
        int min=3001;
        Random random=new Random();
        int[] arr=new int[size];
        List<EsJobCompany> list=new ArrayList<>();
        for (int x=0;x<arr.length;x++) {
            int s = random.nextInt(jobId) % (jobId - min + 1) + min;
            arr[x]= s;
            System.out.println("***************************************sssss*******************************************************" + arr[x]);
            if (arr[x] <= jobId) {
                JobDetail jobs = jobDetailMapper.selectById(arr[x]);
                CompanyDetail companyDetail = companyDetailMapper.selectById(jobs.getCompanyId());
                EsJobCompany esJobCompany = new EsJobCompany();
                esJobCompany.setJobType(jobs.getJobType());
                esJobCompany.setJobId(jobs.getJobId());
                esJobCompany.setCompanyImg(companyDetail.getCompanyImg());
                esJobCompany.setJobName(jobs.getJobName());
                esJobCompany.setCompanyScale(companyDetail.getCompanyScale());
                esJobCompany.setCompanyName(companyDetail.getCompanyName());
                esJobCompany.setCompanyFinance(companyDetail.getCompanyFinance());
                esJobCompany.setJobExperience(jobs.getJobExperience());
                esJobCompany.setJobMinSalary(jobs.getJobMinSalary());
                esJobCompany.setJobMaxSalary(jobs.getJobMaxSalary());
                esJobCompany.setCompanyId(companyDetail.getCompanyId());
                esJobCompany.setJobLocArea(jobs.getJobLocArea());
                esJobCompany.setCompanyIndustry(esJobCompany.getCompanyIndustry());
                esJobCompany.setJobDegree(jobs.getJobDegree());
                list.add(esJobCompany);
            }
        }
        return ServerResponse.success("xxx",list);
    }

//    @Override
//    public ServerResponse saveToCookie(Integer jobId, HttpServletRequest request, HttpServletResponse response) {
//     return null;
//    }

    /**
     * 首页热门职位热数据: redis
     * @return
     */

    @Cacheable(value = "hotJobList#1#d", key = "'hot_JobList'")
    @Override
    public ServerResponse getJobAndCompany() {
        PageHelper.startPage(1,9);
        QueryWrapper<JobDetail> wapper = new QueryWrapper<>();
        wapper.orderByAsc("job_pub_time");
        List<JobDetail> jobDetailList = jobDetailMapper.selectList(wapper);
        List<JobAndCompany> jobAndCompanyList = new ArrayList<>();
        for (JobDetail jobdetail:jobDetailList){
            CompanyDetail companyDetail = companyDetailMapper.selectById(jobdetail.getCompanyId());
            JobAndCompany JObAndCompany = new JobAndCompany(jobdetail,companyDetail);
            jobAndCompanyList.add(JObAndCompany);
        }
        System.out.println("从数据库中获取数据:====" +jobAndCompanyList );
        if (jobAndCompanyList != null){
            PageInfo<JobAndCompany> pageInfo = new PageInfo<>(jobAndCompanyList);
            jobAndCompanyList.forEach(System.out::println);

            return ServerResponse.success("查询所有成功",pageInfo);
        }
        return ServerResponse.fail("查询所有失败",null);
    }



    //后台

    @Override
    public List<JobDetail> selectAllByPage(JobDetailVo jobDetailVo, HttpSession session) {
        CompanyManage companyManage = (CompanyManage) session.getAttribute("loginuser");
        QueryWrapper<JobDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("company_id",companyManage.getCompanyId());
        List<JobDetail> jobDetails2 = jobDetailMapper.selectList(wrapper);
        List<JobDetail> jobDetails1 = jobDetailMapper.selectAllByPage(jobDetailVo);
        List<JobDetail> jobDetails = new ArrayList<>();
        for (JobDetail jobDetail : jobDetails1) {
            for (JobDetail jobDetail1:jobDetails2) {
                if(jobDetail.getJobId().equals(jobDetail1.getJobId())){
                    jobDetails.add(jobDetail);
                }
            }
        }
        return jobDetails;
    }

    @Override
    public List<JobDetail> selectAllByPagePerson(JobDetailVo jobDetailVo, HttpSession session) {
        CompanyManage companyManage = (CompanyManage) session.getAttribute("loginuser");
        QueryWrapper<JobDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("company_id",companyManage.getCompanyId());
        wrapper.eq("manage_id",companyManage.getManageId());
        List<JobDetail> jobDetails2 = jobDetailMapper.selectList(wrapper);
        List<JobDetail> jobDetails1 = jobDetailMapper.selectAllByPage(jobDetailVo);
        List<JobDetail> jobDetails = new ArrayList<>();
        for (JobDetail jobDetail : jobDetails1) {
            for (JobDetail jobDetail1:jobDetails2) {
                if(jobDetail.getJobId().equals(jobDetail1.getJobId())){
                    jobDetails.add(jobDetail);
                }
            }
        }
        return jobDetails;
    }

    @Override
    public Boolean savaJob(JobDetail jobDetail) {
        int insert = jobDetailMapper.insert(jobDetail);
        return insert>0;
    }

    @Override
    public Boolean updateJob(JobDetail jobDetail) {
        int i = jobDetailMapper.updateById(jobDetail);
        return i>0;
    }

    @Override
    public Boolean deleteJob(Integer id) {
        int delete = jobDetailMapper.deleteById(id);
        return delete>0;
    }

    @Override
    public JobDetail selectById(Integer id) {
        JobDetail jobDetail = jobDetailMapper.selectById(id);
        return jobDetail;
    }
}
